package labox.innovation.gameserver.network.serverpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;
import labox.innovation.gameserver.network.L2GameClient;
import labox.innovation.netcore.SendablePacket;

/**
 * 
 * @author KenM
 */
public abstract class L2GameServerPacket extends SendablePacket<L2GameClient> {

	private static final Logger _log = LoggerFactory.getLogger(L2GameServerPacket.class.getName());

	/*------------------------------������ɫ����½����--------------------------------*/

	/**
	 * �ͻ��˵ĳ�ʼ��α����key
	 * 
	 */
	public static final int PTL_KEYPACKET = 0x10;

	/**
	 * ��ɫѡ���б?���͸�ͻ�������ѡ���½�Ľ�ɫ�б�
	 * 
	 */
	public static final int PTL_CHARSELECTIONINFO = PTL_KEYPACKET + 0x01;

	/**
	 * ��½ʧ�ܵ���Ϣ
	 */
	public static final int PTL_LOGINFAIL = PTL_KEYPACKET + 0x02;

	/**
	 * ���Դ����Ľ�ɫģ��
	 */
	public static final int PTL_NEWCHARACTERSUCCESS = PTL_KEYPACKET + 0x03;

	/**
	 * ������ɫʧ��
	 */
	public static final int PTL_CHARCREATEFAIL = PTL_KEYPACKET + 0x04;

	/**
	 * �ǳ�
	 */
	public static final int PTL_LEAVEWORLD = PTL_KEYPACKET + 0x05;

	/**
	 * ����У��
	 */
	public static final int PTL_GAMEGUARDQUERY = PTL_KEYPACKET + 0x06;

	/**
	 * ����ɾ��Ľ��
	 */
	public static final int PTL_CHARDELETERESULT = PTL_KEYPACKET + 0x07;

	/*------------------------------������ɫ����--------------------------------*/

	/**
	 * ���ͽ�ɫ����Ϣ
	 */
	public static final int PTL_USERBASEINFO = 0x20;

	/**
	 * ��ɫ����״̬�ȸ���Э��
	 */
	public static final int PTL_STATUSUPDATE = PTL_USERBASEINFO + 1;

	/**
	 * ���͸�ͻ���ĳ�������ϵĵ�ͼ���
	 */
	public static final int PTL_SCENEMAP = PTL_USERBASEINFO + 2;

	/**
	 * ���Ϳͻ��˵�ĳһ�������
	 */
	public static final int PTL_TELEPORTTOLOCATION = PTL_USERBASEINFO + 3;

	/**
	 * ������ҽ�ɫ���ͬ��Э��
	 */
	public static final int PTL_CHARINFO = PTL_USERBASEINFO + 4;

	/**
	 * ע��NPCЭ��
	 */
	public static final int PTL_ABSTRACTNPCINFO = PTL_USERBASEINFO + 5;

	/**
	 * һ����û�й����߼����������߼�ֻ�������Ķ���Э��
	 */
	public static final int PTL_SERVEROBJECTINFO = PTL_USERBASEINFO + 6;

	/**
	 * ɾ��һ������
	 */
	public static final int PTL_DELETEOBJECT = PTL_USERBASEINFO + 7;

	/**
	 * ָ��ĳ�������һ������ߵ���һ�����
	 */
	public static final int PTL_MOVETOLOCATION = PTL_USERBASEINFO + 8;

	/**
	 * ��ͻ���ע��Ŀ�ݷ�ʽ
	 */
	public static final int PTL_SHORTCUTREGISTER = PTL_USERBASEINFO + 9;

	/**
	 * ��ͻ���ɾ���ݷ�ʽ
	 */
	public static final int PTL_SHORTCUTDEL = PTL_USERBASEINFO + 0x0a;

	/**
	 * �������·��ͻ�������������ϸ��Ϣ
	 */
	public static final int PTL_USERINFO = PTL_USERBASEINFO + 0x0b;

	/**
	 * �������¿�ݷ�ʽ�б�
	 */
	public static final int PTL_SHORTCUTLIST = PTL_USERBASEINFO + 0x0c;

	/**
	 * ��������б�
	 */
	public static final int PTL_NEARBYCHARACTERPACKET = PTL_USERBASEINFO + 0xd;

	/**
	 * ���뷢����������ӵ�Э��
	 */
	public static final int PTL_ASKJOINPARTY = PTL_USERBASEINFO + 0xf;

	/**
	 * ������Ϣ
	 */
	public static final int PTL_PARTYINFOPACKET = PTL_USERBASEINFO + 0x10;

	/**
	 * �ӳ�
	 */
	public static final int PTL_PARTYLEADER = PTL_USERBASEINFO + 0x11;

	/**
	 * �·��¶�Ա��Ϣ
	 */
	public static final int PTL_NEWPARTYMEMBERINFO = PTL_USERBASEINFO + 0x12;

	/**
	 * �·������Ա��Ϣ
	 */
	public static final int PTL_ALLPARTYMEMBERINFO = PTL_USERBASEINFO + 0x13;

	/**
	 * �·�ɾ���Ա��Ϣ
	 */
	public static final int PTL_DELPARTYMEMBERINFO = PTL_USERBASEINFO + 0x14;

	/**
	 * �·�ɾ�����ж�Ա��Ϣ
	 */
	public static final int PTL_DELALLPARTYMEMBERINFO = PTL_USERBASEINFO + 0x15;

	/**
	 * �·�������䷽ʽ
	 */
	public static final int PTL_PARTYCHANGEDISTRIBUTION = PTL_USERBASEINFO + 0x16;

	/**
	 * �·����¶�Ա��Ϣ
	 */
	public static final int PTL_UPDATEPARTYMEMBERINFO = PTL_USERBASEINFO + 0x17;

	/**
	 * �·�������
	 */
	public static final int PTL_ALLSKILLDATA = PTL_USERBASEINFO + 0x18;

	/**
	 * �·�����������Ϣ
	 */
	public static final int PTL_SKILLINFO = PTL_USERBASEINFO + 0x19;

	/**
	 * �·���ҽ������
	 */
	public static final int PTL_GUILIST = PTL_USERBASEINFO + 0x1a;

	/**
	 * �·��ͻ��˽ű�����
	 */
	public static final int PTL_CLIENTSCRIPTHANDLE = PTL_USERBASEINFO + 0x1b;

	/**
	 * �·���ͻ�����ұ����NPC�ֿ���Ʒ�б���Ϣ
	 */
	public static final int PTL_INVENTORY_MERCHANT_LIST = PTL_USERBASEINFO + 0x1C;

	/**
	 * �·���ͻ���NPC�����ɹ��Ժ󱳰�ָ�����Ʒ��Ϣ
	 */
	public static final int PTL_MERCHANT_UPDATE = PTL_USERBASEINFO + 0x1D;

	/**
	 * �·������ͼ
	 */
	public static final int PTL_WORLDMAP = PTL_USERBASEINFO + 0x1E;

	/**
	 * �·��״������
	 */
	public static final int PTL_RADARCONTROL = PTL_USERBASEINFO + 0x1F;

	/*------------------------------ս����������--------------------------------*/

	/**
	 * ֪ͨ�ͻ����Զ������Ķ�����ʼ
	 */
	public static final int PTL_AUTOATTACKSTART = 0x50;

	/**
	 * ���������صĽ���/ս����Actionʧ�ܵ�Э��
	 */
	public static final int PTL_ACTIONFAILED = PTL_AUTOATTACKSTART + 1;

	/**
	 * ֪ͨ�ͻ����Զ������Ķ�������
	 */
	public static final int PTL_AUTOATTACKSTOP = PTL_AUTOATTACKSTART + 2;

	/**
	 * ֪ͨ�ͻ���ĳ�����������
	 */
	public static final int PTL_DIE = PTL_AUTOATTACKSTART + 3;

	/**
	 * �������֪ͨ��
	 */
	public static final int PTL_ATTACK = PTL_AUTOATTACKSTART + 4;

	/**
	 * ���Ϳͻ��˽������������
	 */
	public static final int PTL_NPCHTMLMESSAGE = PTL_AUTOATTACKSTART + 5;

	/**
	 * ����Э��
	 */
	public static final int PTL_REVIVE = PTL_AUTOATTACKSTART + 6;

	/**
	 * ֪ͨ�ͻ��� ʹ����ĳ���� ��Ϣ
	 */
	public static final int PTL_MAGICSKILLUSE = PTL_AUTOATTACKSTART + 7;

	/**
	 * ֪ͨ�ͻ��� ʹ�ü���
	 */
	public static final int PTL_MAGICSKILLLAUNCHED = PTL_AUTOATTACKSTART + 8;

	/**
	 * ֪ͨ�ͻ��� Ч��Э��
	 */
	public static final int PTL_EFFECTACTION = PTL_AUTOATTACKSTART + 9;

	/**
	 * �·�Ч��״̬
	 */
	public static final int PTL_EFFECTSTATS = PTL_AUTOATTACKSTART + 0x0a;

	/**
	 * �·�PKģʽ
	 */
	public static final int PTL_PKMODEL = PTL_AUTOATTACKSTART + 0x0b;

	/**
	 * �������·��Զ�ս��������Ϣ
	 */
	public static final int PTL_AUTOATTACKINFO = PTL_AUTOATTACKSTART + 0x0c;

	/*------------------------------������������--------------------------------*/

	/**
	 * ������ƷЭ��
	 */
	public static final int PTL_ITEMLIST = 0x70;

	/**
	 * ������ƷЭ��
	 */
	public static final int PTL_EXRPITEMLINK = PTL_ITEMLIST + 1;

	/**
	 * ���� �ֲ�����
	 */
	public static final int PTL_INVENTORYUPDATE = PTL_ITEMLIST + 2;

	/**
	 * ֪ͨ���׶Է�������
	 */
	public static final int PTL_SENDTRADEREQUEST = PTL_ITEMLIST + 3;

	/**
	 * ֪ͨ���׿�ʼ
	 */
	public static final int PTL_TRADESTART = PTL_ITEMLIST + 4;

	/**
	 * ֪ͨ�����б�仯
	 */
	public static final int PTL_TRADEITEMCHANGE = PTL_ITEMLIST + 5;

	/**
	 * ֪ͨ����״̬�仯
	 */
	public static final int PTL_TRADESTATS = PTL_ITEMLIST + 6;

	/**
	 * ֪ͨ���׽���
	 */
	public static final int PTL_TRADEDONE = PTL_ITEMLIST + 7;

	/**
	 * �������·��ֿⱳ��
	 */
	public static final int PTL_WAREHOUSE_INVENTORY = PTL_ITEMLIST + 8;

	/**
	 *������֪ͨ�ֿ�/������Ʒ����
	 */
	public static final int PTL_WAREHOUSE_INVENTORY_UPDATE = PTL_ITEMLIST + 9;

	/**
	 * �·� ���Զ������Ʒ���
	 */
	public static final int PTL_FORGEITEMDATA = PTL_ITEMLIST + 0x0a;

	/**
	 * ������Ʒ�ı�
	 */
	public static final int PTL_FORGEITEMCHANGE = PTL_ITEMLIST + 0x0b;

	/**
	 * ����ɹ�
	 */
	public static final int PTL_FORGEITEMSUCESS = PTL_ITEMLIST + 0x0c;
	
	/*------------------------------����ϵͳ����Э��--------------------------------*/
	/**
	 * �����Э��
	 */
	public static final int PTL_CHAT_BASE = 0x90;
	
	/**
	 * �·�ϵͳ��Ϣ
	 */
	public static final int PTL_SYSTEM_MESSAGE = PTL_CHAT_BASE + 1;
	
	/**
	 * �ظ��ͻ������쿪��������Ϣ
	 */
	public static final int PTL_CHAT_SWITCHES = PTL_CHAT_BASE + 2;

	/*------------------------------����ϵͳ����Э��--------------------------------*/
	/**
	 * �����б�Э��
	 */
	public static final int PTL_FREINDLIST = 0xA0;

	/**
	 * ��Ӧ��������
	 */
	public static final int PTL_ANSERSEARCHFRIENDREQUEST = PTL_FREINDLIST + 1;

	/**
	 * ��Ӧ���Ѷ�̬����
	 */
	public static final int PTL_ANSERFRIENDNEWSREQUEST = PTL_FREINDLIST + 2;

	/*------------------------------����ϵͳ����Э��--------------------------------*/
	/**
	 * ����UI
	 */
	public static final int PTL_CONSIGNMENTUI = 0xB0;

	/**
	 * ���ϼ���Ʒ
	 */
	public static final int PTL_CANSHELVEITEMS = PTL_CONSIGNMENTUI + 1;

	/**
	 * ���Ҽ�����Ʒ���
	 */
	public static final int PTL_CONITEMHIGHPACKET = PTL_CONSIGNMENTUI + 2;

	/**
	 * �ɹ����������Ʒ
	 */
	public static final int PTL_BUYCONSITEMRESULTPACKET = PTL_CONSIGNMENTUI + 3;

	protected boolean _invisible;

	/**
	 * 
	 * @return True if packet originated from invisible character.
	 */
	public boolean isInvisible() {
		return _invisible;
	}

	/**
	 * Set "invisible" boolean flag in the packet. Packets from invisible characters will not be broadcasted to players.
	 * 
	 * @param b
	 */
	public void setInvisible(boolean b) {
		_invisible = b;
	}

	/**
	 * @see com.l2jserver.mmocore.network.SendablePacket#write()
	 */
	@Override
	protected void write() {
		try {
			//System.out.println("getType():"+getType());
			writeImpl();
		} catch (Exception e) {
			_log.error("Client: " + getClient().toString() + " - Failed writing: " + getType() + " - Innovation Server Version: " + Config.SERVER_VERSION + " - DP Revision: " + Config.DATAPACK_VERSION, Config.SERVER_ID, e);
		}
	}

	public void runImpl() {

	}

	protected abstract void writeImpl();

	/**
	 * @return A String with this packet name for debug purposes
	 */
	public abstract String getType();
}
